var userId;
window.onload = function (){
    userId=getQuery("id");

}

function changePwd(){
    axios.get("/user/getLoginUser",{
        params: {
            id:userId
        }
    }).then(resp => {
        var info = resp.data;

        if (info === "noland"){
            location.href="/login.html?errorInfo=noland";
        }

        if ($("oldPwd").value !== info.pwd){
            $("oldErrorSpan").innerHTML="密码错误";
            $("newErrorSpan").innerHTML="";
        }
        else if ($("newPwd").value === "" || $("newPwd2").value === ""){
            $("newErrorSpan").innerHTML="密码不能为空";
            $("oldErrorSpan").innerHTML="";
        }

        else if ($("newPwd").value !== $("newPwd2").value){
            $("newErrorSpan").innerHTML="前后密码输入不一致";
            $("oldErrorSpan").innerHTML="";
        }
        else {
            axios.get("/user/updateUserPwd",{
                params: {
                    id:userId,
                    pwd:$("newPwd2").value
                }
            }).then(resp =>{
                var info = resp.data;
                if (info === "ok"){
                    alert("修改成功");
                    $("oldPwd").value="";
                    $("newPwd").value="";
                    $("newPwd2").value="";
                    $("oldErrorSpan").innerHTML="";
                    $("newErrorSpan").innerHTML="";
                }
            })
        }
    })


}